package serverClient;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import orders.Customer;
import orders.Order;

/*
 * Server socket
 */
public class Servers {
	private ServerSocket serverSocket;

//	public static Map<String, Customer> customers = new HashMap<String, Customer>();

	public Servers(int port) throws IOException {
		serverSocket = new ServerSocket(port);
		// serverSocket.setSoTimeout(10000);
	}

	/*
	 * server loop to wait client connect
	 * create new thread when client connect
	 */
	public void start() {
		System.out.println("Server is ready...");
		int count = 0;
		while (true) {
			try {
				Socket socket = serverSocket.accept();
				System.out.println("Client " + (++count));
				new ServerThread(socket).start();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
